package com.sunky.rfidapp

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.Gravity
import android.widget.Toast
import com.sunky.db.greendao.*
import com.sunky.db.util.DBManager
import kotlinx.android.synthetic.main.layout_title.*

open abstract class BaseActivity : Activity(){

    val configDao : UserConfigDao by lazy {
        DBManager.getInstance().daoSession.userConfigDao
    }
    val equipDao : EquipInfoDao by lazy {
        DBManager.getInstance().daoSession.equipInfoDao
    }

    val chipperDao : ChiperEquipInfoDao by lazy {
        DBManager.getInstance().daoSession.chiperEquipInfoDao
    }

    val checkRecordDao : CheckRecordDao by lazy {
        DBManager.getInstance().daoSession.checkRecordDao
    }
    //V2新增
    val equipDaoV2 : EquipInfoV2Dao by lazy {
        DBManager.getInstance().daoSession.equipInfoV2Dao
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        handleIntent(intent)
        setContentView(getLayoutId())
        initView()
        setViewDefault()
        initData()
    }
    open fun handleIntent(intent : Intent){}

    abstract fun getLayoutId():Int

    abstract fun initView()

    abstract fun initData()

    private fun setViewDefault(){
        TvBack?.setOnClickListener {
            finish()
        }
    }

    fun openActivity(activityClass : Class<out Activity>){
        var intent = Intent(this,activityClass)
        startActivity(intent)
    }

    fun toast(msg : String){
        var toast = Toast.makeText(this,msg,Toast.LENGTH_SHORT)
        toast.setGravity(Gravity.CENTER,0,0)
        toast.show()
    }
}